package _1_PIO.excel.样式;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 边界处理
 */
public class _2_Borders {

    @Test
    public void _2003(){

    }

    @Test
    public void _2007() throws IOException {

        Workbook workbook = new XSSFWorkbook();

        Sheet sheet = workbook.createSheet("new Shell");

        Row row = sheet.createRow(1);

        Cell cell = row.createCell(1);
        cell.setCellValue("jby");

        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());

        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setRightBorderColor(IndexedColors.RED.getIndex());

        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setRightBorderColor(IndexedColors.BLUE.getIndex());

        cellStyle.setBorderTop(BorderStyle.MEDIUM_DASHED);
        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
        cell.setCellStyle(cellStyle);

        try(OutputStream outputStream = new FileOutputStream("D://workbook.xlsx")){
            workbook.write(outputStream);
        }
        finally {
            workbook.close();
        }
    }
}
